package com.abvnet.project.water.project.service;

import com.abvnet.common.utils.text.Convert;
import com.abvnet.project.water.project.domain.ProjectCustomerEvaluate;
import com.abvnet.project.water.project.mapper.ProjectCustomerEvaluateMapper;
import com.abvnet.project.water.project.mapper.ProjectInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户评估 服务层实现
 * 
 * @author duj
 * @date 2019-08-21
 */
@Service
public class ProjectCustomerEvaluateServiceImpl implements IProjectCustomerEvaluateService {
	@Autowired
	private ProjectCustomerEvaluateMapper projectCustomerEvaluateMapper;

	@Autowired
    private ProjectInfoMapper projectInfoMapper;

	/**
     * 查询客户评估信息
     * 
     * @param evaluateId 客户评估ID
     * @return 客户评估信息
     */
    @Override
	public ProjectCustomerEvaluate selectProjectCustomerEvaluateById(Long evaluateId) {
	    return projectCustomerEvaluateMapper.selectProjectCustomerEvaluateById(evaluateId);
	}

    @Override
    public ProjectCustomerEvaluate selectProjectCustomerEvaluateByProjectId(Long projectId) {
        return projectCustomerEvaluateMapper.selectProjectCustomerEvaluateByProjectId(projectId);
    }

    /**
     * 查询客户评估列表
     * 
     * @param projectCustomerEvaluate 客户评估信息
     * @return 客户评估集合
     */
	@Override
	public List<ProjectCustomerEvaluate> selectProjectCustomerEvaluateList(ProjectCustomerEvaluate projectCustomerEvaluate) {
	    return projectCustomerEvaluateMapper.selectProjectCustomerEvaluateList(projectCustomerEvaluate);
	}
	
    /**
     * 新增客户评估
     * 
     * @param projectCustomerEvaluate 客户评估信息
     * @return 结果
     */
	@Override
	public int insertProjectCustomerEvaluate(ProjectCustomerEvaluate projectCustomerEvaluate) {
	    return projectCustomerEvaluateMapper.insertProjectCustomerEvaluate(projectCustomerEvaluate);
	}
	
	/**
     * 修改客户评估
     * 
     * @param projectCustomerEvaluate 客户评估信息
     * @return 结果
     */
	@Override
	public int updateProjectCustomerEvaluate(ProjectCustomerEvaluate projectCustomerEvaluate) {
        int projectPrice = projectCustomerEvaluate.getProjectPrice();
        Integer projectRate = 0;
        if (projectPrice < 5000) {
            projectRate = 50;
        }else if (projectPrice >= 5000 && projectPrice < 10000) {
            projectRate = 60;
        } else if (projectPrice >= 10000 && projectPrice < 30000) {
            projectRate = 70;
        } else if (projectPrice >= 30000 && projectPrice < 100000) {
            projectRate = 80;
        } else if (projectPrice >= 100000 && projectPrice < 200000) {
            projectRate = 90;
        } else if (projectPrice >= 200000) {
            projectRate = 100;
        }
        projectCustomerEvaluate.setProjectPrice(projectPrice);
        projectCustomerEvaluate.setEvalRate(Integer.valueOf(projectCustomerEvaluate.getEvalType())*20);
        projectCustomerEvaluate.setProjectRate(projectRate);
        Integer customerRate =
                (projectRate * 40 + projectCustomerEvaluate.getEvalRate() * 30 + projectCustomerEvaluate.getDiscountRate() * 30) / 100;
        projectCustomerEvaluate.setCustomerRate(customerRate);
	    return projectCustomerEvaluateMapper.updateProjectCustomerEvaluate(projectCustomerEvaluate);
	}

	/**
     * 删除客户评估对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteProjectCustomerEvaluateByIds(String ids) {
		return projectCustomerEvaluateMapper.deleteProjectCustomerEvaluateByIds(Convert.toStrArray(ids));
	}
}